﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Text;
using System.Web.Script.Serialization;
using Assignment_3.Classes;

namespace Assignment_3.Feature___Reports
{
    public partial class GeneralReport : System.Web.UI.Page
    {
        #region Control Methods
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null || Session["usertype"] == null)
            {
                Response.Redirect("~/Feature - Users/Login.aspx");
            }

            roomnoVld.Validate();
        }

        protected void roomnoTbx_TextChanged(object sender, EventArgs e)
        {
            ArrayList generalList = new ArrayList();
            emptyLbl.Text = "";
            if (Page.IsValid)
            {
                generalList = DatabaseManager.getGeneralReport(roomnoTbx.Text);

                //Check if got records
                if (generalList.Count != 0)
                {
                    chartPanel.Visible = true;
                }
                else
                {
                    emptyLbl.Text = "No Data found for this room number!";
                    chartPanel.Visible = false;
                }

                //Draw Table Chart
                StringBuilder data = new StringBuilder();
                JavaScriptSerializer json = new JavaScriptSerializer();
                json.Serialize(generalList, data);
                hdData.Value = data.ToString();

                //Number of people
                int count = generalList.Count;
                totalLbl.Text = Convert.ToString(count);

                //Status of the room (Vacant/Occupied)
                statusLbl.Text = DatabaseManager.getGeneralStatus(roomnoTbx.Text);
            }
        }
        #endregion

    }
}